package com.chinaoly.baotou.common.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RsaUtil {

    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQZ7a/DGt0zuWHdT2JxXZX4cxSOeo8SB0BKkqYzdPw1fxwiP/JkjiMY6CaJyj+hcjvSR6r7AbWVjFc7fwmLDfPzYJ/rH9CQ0J5rnEeTmt2Zbum9jnxH3LVTLuXkARxnXopLQHUo+YOOuoD29ig5C6yb1cCTL5vE+kI1xzVsM1FgwIDAQAB";

    public static String encrypt(String content) throws Exception {
        RSA rsa = new RSA(PRIVATE_KEY, PUBLIC_KEY);
        return rsa.encryptBase64(content, KeyType.PublicKey);
    }

    private static final String PRIVATE_KEY = "MIIEowIBAAKCAQEArKEagVUFzcuNIPBqfNib8flWb/TzP+RqKnauMspwIh75klxH" +
            "2gbtK854KQmB8tlTbwjw+SMv50rUYtC7gm7ER8LEGrmxIXFlgYIwm2Qp5+8723ys" +
            "8boJ/OuMKeWOAxzUllcjkdhWq6TBtWQepLY3otCTkLEMc2ZBV/18SIPJJqpzKHCH" +
            "sfi+GasHt0XubeyvbxymBDr1q/tPPM9bk1wyhuY6RZGPPfbQWQrGJxyTXvY6cLYo" +
            "eI7E7MjgrjMWTjK8T8Ymrhf1OmUYMXFuvtfwzXrhnDKJykb96MmNpq7uW0H8xokG" +
            "eBUcjZQAHS+Iua5JHU+hZmesfDHlcIx2htvHpQIDAQABAoIBAARq1u/KSiy68bCP" +
            "Flp9fHgTpkeVIAhZgvH1OX3pOjdVTZOWMux8UuNVFDQQnzekogLsWqY1ZUto2chx" +
            "iOrMhM9FR5lbeRHfAfbvauj/Bid+MqzqIs7IsOq86EhGLH0d5r62Gh3oSEd6Hs7S" +
            "cgpK81+CMNR6A1SMoE1tGhoM7T/FAAfOOvftWXvRkLK1+hQO5SPxTKZMT5WvVA/1" +
            "ljcWrqnJl9udp19OWP6ZS0Ijj7tfhhGB7yz8dzgfS2OZK17GplCBm+kMDyHOERPZ" +
            "4Wxd2pWQdKlx6rUIVyBRR9XXi0hP8ZEjLSvARnO5Bnp8MU+TL+/tL8NMxURO0kem" +
            "DXbrBIECgYEA37lBY0tRLV2GJQyIIkPBgOho/+3XRuJXtOju+6oCWS3en64TBOnE" +
            "PMm/bYmMqzU12qtCbmQ2B/nWUGB6vU22QEXyr88an/+YDRPzLcHnX39rY736vmUB" +
            "/GJpiseGDMiWMihPrmyoUgshb0uTA6TXi3VkkQGaywAtNtHYYobSgaECgYEAxYjK" +
            "Rc7eTib+fZFzVbNBcFg6WfmLPOikGXGyjUyXaAHTTD+j8Tk4e+gYOqEZxdN2kzX1" +
            "EqF0CB4R7qjr8wmkd0hF5BIiGFd4L5yo9HiL+fYgP8DR840a2W3jbC8XnL+ERcwP" +
            "Khtir1ZpEgnWjzEoBumKVEAU/9m77eY/R+gmD4UCgYEApBKZ6LcwxoNjQMKLCA4G" +
            "2IIZlzAXhE20ouF9eqV46Wwha5vfKOhD2YzfzfZlap4wa7jTlF/73CeWzAWlnjVi" +
            "5ool7FeHoDVzjovF+RXOmJO670BBpuYu6ahG3Nds8O0ecZRss2/OlbTCBXw4SiDX" +
            "Tth+M3Yozp3Hiv+koMVdlmECgYANmX1TkQp9FvIucvUd0VmQAoMB7sxHRT0HA2zn" +
            "jX5fCsEhXsBKu0XIQhJo9u5vUD+5ot1ciwESDf/uDnMwKFnKXI9zRExUoLEFliOL" +
            "sUDx1KAjw4Kw4eYXUhl2OUfG4uiYZZQlsfz5VVmmhEbhVOEMmMeNRVwswTDPECsL" +
            "KFB2gQKBgAnJV9mpnZ3KR7CP69ufekWCRkzFGQuZB0k+KE0BIC26KcqGKnJrd2dL" +
            "z227i/KEX/nt9Xqi/lu7ghI8ShgCzZ2GeU28gN9Au3+UrRDvWj+LeQqrc2AvjjmO" +
            "4GK5Np5BmkyZlpZZfBEmzN42y34zm1Va9GXX3oQmOrLbXEmDbiB9";

    public static void decrypt(String content) {
        RSA rsa = new RSA(PRIVATE_KEY, PUBLIC_KEY);
        System.out.println(rsa.decrypt(content.getBytes(), KeyType.PrivateKey));
    }

    public static void main(String[] args) {
        String aa = "VVZSRmVFMVVTVVZCTkZKclZUQk5WRlpFVDBSWk5VMVVZelZSZWtreFRtdE5lVkpFVFRWTlJGRjVUVVJPVUUxcVNUQk5lbFY1VW10V1EwNUVWVEZPTUUwelRucFpORTFWVGtWTlZGazBUa1ZSTTA1RlJUSk5lbEUxVG10TmQxRXdUa1JPYW1ONFRsUk9RazVFVVhwUFJGSkVVbXBSZVU0d1VrTlJla1V3VFdwWk1FNTZTWHBQUlZrelQwUmpNRkpVWnpWTk1GcEdUWHBuZWs1cVozZE9SR3hEVG1wT1JFNVZTVEpQVlZFelRUQkpNMDVVVFhwU1JHaEZUMVZTUkZKVVFrTlBSRUY0VG1wa1ExSnJWa0pTYWxaQ1QxVktSVTFWVlRKT2FtUkNVa1ZLUTA1RVdrZE5ha0pDVGxSRk5GRlVhekpQVkUxNlVWVkpkMDVVUmtkUk1FVXdUa1JGZDFKVldUUlJWRkY1VFZSU1JsSlVZekZOZWtreFRsVlJORkpyV1hkTmFsVjVVVlZLUms1VlZUTk5SVlY0VDFSYVJrMUVZek5SVkUweFRWVkdRbEpyVVhwTlJVWkhUa1JWZDFKcVZYcE9ha1UwVWxSamQwNUVSVEpPZWxwRFRrUktSazVVVFRCTmVrRTFUMFJTUkZKRlJYbFNha0V3VG5wV1JFMVVUVFZOUlU1RlRucFJlVTFVWkVST1JGRjZVV3BSTkU5RVJrTlNSRkpDVG1wV1JVOUVVVFJTUlZKRVVsUnJkMDVVUlhkU2FsRTBVbXRWTkZKcVVrVlJlbXQ2VG1wSmVFNTZiRVZOVlZsNVVYcEpORTB3V1hwUFZVMHlVV3BGTVUxNlFrSlJhazB3VDBSamVrNXFhelZSVkVKRVVrVlplazR3V2tKUlZWWkdVbFJKZWxKVVNUQk9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